package io.libp2p.example.chat;

import android.content.Context;
import android.text.TextUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class StunText {

    public static List<String> stunList = new ArrayList<>();

    public static List<String> getStunList() {
        return stunList;
    }

    public static void readText(Context context){
        InputStream inputStream = context.getResources().openRawResource(R.raw.stun);

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            // 将 BufferedReader 转换为 Stream<String>
            Stream<String> lines = reader.lines();
            // 遍历每一行
            lines.forEach(str ->{
                String stun = str.trim();
                //MyLog.D("StunText stun:"+stun);
                if(!TextUtils.isEmpty(str)) {
                    if(stunList.size() < 3) {
                        stunList.add("stun:" + stun);
                    }
                }
            });

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
